package com.code.demo.binding;

import android.databinding.BindingAdapter;
import android.widget.ImageView;

import com.code.demo.R;
import com.bumptech.glide.Glide;

/**
 * Created by yangliguo on 2018/4/5.
 */

public class BindingCustom {

    @BindingAdapter(value = {"imageUrl", "imageType"}, requireAll = false)
    public static void setImageUrl(ImageView view, String url, String type) {
        if (type != null && type.equals("fit")) {
            Glide.with(view.getContext())
                    .load(url)
                    .fitCenter()
                    .placeholder(R.mipmap.pic_defalut_200)
                    .into(view);
        } else {
            Glide.with(view.getContext())
                    .load(url)
                    .placeholder(R.mipmap.pic_defalut_200)
                    .into(view);
        }
    }
}
